home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / xprogs.arc / ITOA.C next >
Text File  |  1987-11-19  |  406b  |  25 lines

  1. char    *itoa(num)
  2. unsigned int    num;
  3. {
  4.     long    digits[6]={1,10,100,1000,10000,100000};
  5. static    char    str[10];
  6.     int      max,i;
  7.  
  8.     if (num<2)
  9.     {
  10.         max=1;
  11.         str[0]='0';
  12.     }
  13.     else
  14.         for (max=0;(max<6 && (long) num>digits[max]);str[max++]='0');
  15.     str[max]='\0';
  16.     if (num>0)
  17.         for (i=max;i>=0;--i)
  18.             while ((long) num-digits[i]>=0)
  19.             {
  20.                 str[max-1-i]++;
  21.                 num-=digits[i];
  22.             };
  23.     return(str);
  24. }
  25.